package com.zhz.service.impl;

import java.sql.Connection;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.zhz.dao.BillMapper;
import com.zhz.dao.ProviderMapper;
import com.zhz.pojo.Provider;
import com.zhz.service.ProviderService;

@Service("providerService")
public class ProviderServiceImpl implements ProviderService {
	@Resource(name="providerMapper")
	private ProviderMapper providerMapper;
	@Resource(name="billMapper")
	private BillMapper billMapper;

	@Override
	public boolean add(Provider provider) {
		return providerMapper.add(provider) > 0;
	}

	@Override
	public List<Provider> getProviderList(String proName, String proCode) {
		return providerMapper.getProviderList(proName, proCode);
	}

	/**
	 * 业务：根据ID删除供应商表的数据之前，需要先去订单表里进行查询操作 若订单表中无该供应商的订单数据，则可以删除
	 * 若有该供应商的订单数据，则不可以删除 返回值billCount 1> billCount == 0 删除---1 成功 （0） 2 不成功
	 * （-1） 2> billCount > 0 不能删除 查询成功（0）查询不成功（-1）
	 * 
	 * ---判断 如果billCount = -1 失败 若billCount >= 0 成功
	 */
	@Override
	public int deleteProviderById(String delId) {
		Connection connection = null;
		int billCount = billMapper.getBillCountByProviderId(delId);
		if (billCount == 0) {
			providerMapper.deleteProviderById(delId);
		}

		return billCount;
	}

	@Override
	public Provider getProviderById(String id) {
		return providerMapper.getProviderById(id);
	}

	@Override
	public boolean modify(Provider provider) {
		return providerMapper.modify(provider) > 0;
	}

}
